import Vue from "vue";
import Vuex from "vuex";
import axios from "axios";

Vue.use(Vuex);

export default new Vuex.Store({
    state: {
        get user() {
            return localStorage.getItem("user") !== undefined ? localStorage.getItem("user") : null;
        },
        get bCurData() {
            return sessionStorage.getItem("bCurData") !== undefined ? sessionStorage.getItem("bCurData") : null;
        },
        get wCurData() {
            return sessionStorage.getItem("wCurData") !== undefined ? sessionStorage.getItem("wCurData") : null;
        },
        get gCurData() {
            return sessionStorage.getItem("gCurData") !== undefined ? sessionStorage.getItem("gCurData") : null;
        },
        get tCurData() {
            return sessionStorage.getItem("tCurData") !== undefined ? sessionStorage.getItem("tCurData") : null;
        },
        get eCurData() {
            return sessionStorage.getItem("eCurData") !== undefined ? sessionStorage.getItem("eCurData") : null;
        },
        get cCurData() {
            return sessionStorage.getItem("cCurData") !== undefined ? sessionStorage.getItem("cCurData") : null;
        },
        roles: [],
        todoCount: {}
    },
    mutations: {
        setBCurData(state, {bCurData}) {
            sessionStorage.setItem("bCurData", bCurData);
        },
        setWCurData(state, {wCurData}) {
            sessionStorage.setItem("wCurData", wCurData);
        },
        setGCurData(state, {gCurData}) {
            sessionStorage.setItem("gCurData", gCurData);
        },
        setTCurData(state, {tCurData}) {
            sessionStorage.setItem("tCurData", tCurData);
        },
        setECurData(state, {eCurData}) {
            sessionStorage.setItem("eCurData", eCurData);
        },
        setCCurData(state, {cCurData}) {
            sessionStorage.setItem("cCurData", cCurData);
        },
        setRoles(state, {roles}) {
            state.roles = roles;
        },
        setUser(state, {user}) {
            localStorage.setItem("user", user);
        },
        logout() {
            localStorage.clear();
            sessionStorage.clear();
        },
        setTodoCount(state, todoCount) {
            state.todoCount = todoCount;
        },
        clearCurData() {
            sessionStorage.clear();
        }
    },
    actions: {
        startBQc(context, {bCurData}) {
            context.commit("setBCurData", {
                bCurData: bCurData
            })
        },
        startWQc(context, {wCurData}) {
            context.commit("setWCurData", {
                wCurData: wCurData
            })
        },
        startGQc(context, {gCurData}) {
            context.commit("setGCurData", {
                gCurData: gCurData
            })
        },
        startTQc(context, {tCurData}) {
            context.commit("setTCurData", {
                tCurData: tCurData
            })
        },
        startEQc(context, {eCurData}) {
            context.commit("setECurData", {
                eCurData: eCurData
            })
        },
        startCQc(context, {cCurData}) {
            context.commit("setCCurData", {
                cCurData: cCurData
            })
        },
        userLogin(context, {user}) {
            context.commit("setUser", {
                user: user
            });
        },
        logout(context) {
            context.commit("logout");
            location.reload();
        },
        clearCurData(context) {
            context.commit("clearCurData");
        }
    },
    modules: {}
});
